//Iditarod Trail
//Amelia Bauer, Elise Eiden, Christine Gerardi, Taryn Green
//CSE 20212 2012
/*General pop up window. What message is displayed is determined by passed in value.*/
#include "GenericWindow.h"
#include <QtGui>
#include <QPushButton>
#include <QApplication>
#include <QGridLayout>
#include <QString>
#include <QLabel>
#include <QPalette>
#include <iostream>
#include <string>
#include <QMovie>
#include <QFont>
using namespace std;

//Constructor
GenericWindow::GenericWindow(int num, string name, QString qstr, QTimer *timer, QDialog *parent):QDialog(parent)
{
	clock = timer;
	resize(300,400);
	//Set up for display
	QPalette palette1, palette2;
	QGridLayout *layout = new QGridLayout(this);
	QPushButton *ok = new QPushButton(QString("OK"));
	QPushButton *exit = new QPushButton(QString("Exit"));
	QLabel *space;
	space=new QLabel ("\n\n\n\n");
	QLabel *space2;
	space2=new QLabel ("          ");

	QLabel *box = new QLabel(this);
	box->setAlignment(Qt::AlignCenter | Qt::AlignRight);

	if(num == 1)    	//died window
	{	
		setWindowTitle(QString("Grave"));
		palette1.setBrush(this->backgroundRole(), QBrush(QImage("gravestone.jpg")));
		this->setPalette(palette1);    //use this pointer to set background picture
		QString dogName(name.c_str());
		QString rip("       Here lies ");
		QString fullDisplay = rip.append(dogName);	//Displays dogs name 
		QLabel *text = new QLabel(fullDisplay);
		text->setFont(QFont("Times New Roman",18));
		layout->addWidget(text,0,0);
		layout->addWidget(ok,5,0);
	}
	else if(num == 2)	//rest window
	{
		setWindowTitle(QString("Resting"));
		resize(300,200);
		QLabel *restText = new QLabel(QString("How many days do you want to rest for?\nNo more than 8 days."));
		rest = new QLineEdit(QString("1"));
		layout->addWidget(restText, 1,0);
		layout->addWidget(rest, 1,1);
		layout->addWidget(ok,5,0);
		
	}
	else if(num == 3)	//hunting window
	{	//QLabel *spaces;
		//spaces = new QLabel(".\n");
		setWindowTitle(QString("Hunting"));
		resize(500,490);
		palette2.setBrush(this->backgroundRole(), QBrush(QImage("dogs1.jpg")));
		this->setPalette(palette2);    //use this pointer to set background picture
		QLabel *huntText = new QLabel(qstr);
		layout->addWidget(huntText,1,0);
		layout->addWidget(space, 2,0);
		layout->addWidget(space, 3,0);
		layout->addWidget(space, 4,0);
		layout->addWidget(space, 5, 0);
		layout->addWidget(space,6,0);
		layout->addWidget(space, 7,0);
		layout->addWidget(space, 8,0);
		layout->addWidget(space, 9,0);
		layout->addWidget(space, 10, 0);
		layout->addWidget(space,11,0);
		layout->addWidget(ok,12,0);	
		huntText->setFont(QFont("Times New Roman", 18, QFont::Bold, false));
		huntText-> setStyleSheet("color: forestgreen;"/*"background-color: green;"*/);

	}
	else if(num == 4)	//Wrong way window, just in case for debugging
	{
		setWindowTitle(QString("Losing"));
		resize(300,400);
		QLabel *wrong = new QLabel("You went the wrong way. You lose.");
		layout->addWidget(wrong,0,0);
		layout->addWidget(exit,5,0);
	}
	else if(num == 5)	//Winner window
	{
		setWindowTitle(QString("Congratulations!"));
		resize(400, 269);
		palette1.setBrush(this->backgroundRole(), QBrush(QImage("generalstore5.jpg")));
		this->setPalette(palette1);    //use this pointer to set background picture
		QString musherName(name.c_str());
		QString winning1(" Congratulations! ");
		QString winning2(" wins! ");
		QString fullDisplayWin = winning1.append(musherName).append(winning2);
		QLabel *display = new QLabel(fullDisplayWin);	//Displays player's name 
		layout->addWidget(space, 1,0);
		layout->addWidget(space, 2,0);
		layout->addWidget(space, 3,0);
		layout->addWidget(display,4,0);
		layout->addWidget(exit,5,0);
		display->setFont(QFont("Times New Roman", 18));
		display->setStyleSheet("color:white;""background-color: firebrick;");
		display->setFixedSize(400,25);
	}
	else if(num == 6)	//Lose 
	{
		setWindowTitle(QString("Lost Game"));
		resize(300,400);
		palette1.setBrush(this->backgroundRole(), QBrush(QImage("gravestone.jpg")));
		this->setPalette(palette1);    //use this pointer to set background picture
		QLabel *empty1 = new QLabel("\n\n");
		QString userName(name.c_str());
		QString rip("         Here lies ");
		QString fullDisplay = rip.append(userName);
		QLabel *text = new QLabel(fullDisplay);
		text->setFont(QFont("Times New Roman", 16));
		QLabel *lost = new QLabel("All of your dogs have died. You lose.");
		layout->addWidget(empty1,0,0);
		layout->addWidget(lost,2,0);
		layout->addWidget(text,1,0);
		layout->addWidget(exit,5,0);
		lost->setFont(QFont("Times New Roman", 14));
		lost->setStyleSheet("color:white;" "background-color: red;");
		lost->setFixedSize(300,25);
	}
	else if(num == 7)	//Sarah Palin
	{
		setWindowTitle(QString("Attack by Sarah Palin!"));
		resize(638, 304);
		box->setFixedSize(638,304);
		QLabel *palinStr = new QLabel(qstr);
		palinStr->setFixedSize(300,35);
		palinStr->setFont(QFont("Times New Roman", 18, QFont::Bold, true));
		palinStr->setStyleSheet("color:white;" "background-color: darkgreen;");
		layout->addWidget(space, 1,0);
		layout->addWidget(space, 2,0);
		layout->addWidget(space, 3,0);
		layout->addWidget(palinStr,4,0);
		//start GIF code
		QMovie *palinMovie=new QMovie("palin.gif");
		box-> setMovie(palinMovie);
		palinMovie-> start();
		ok->setFixedSize(300,40);
		layout->addWidget(ok,5,0);
	}
	else if(num == 8)	//Blizzard 
	{
		setWindowTitle(QString("Blizzard!"));
		resize(272,277);
		box->setFixedSize(272, 277);
		QLabel *blizzStr = new QLabel(qstr);
		
		layout->addWidget(blizzStr, 5,0);
		layout->addWidget(space, 1,0);
		layout->addWidget(space, 2,0);
		layout->addWidget(space, 3,0);
		layout->addWidget(space, 4,0);
		layout->addWidget(ok,6,0);
		
		blizzStr->setFixedSize(250,35);
		blizzStr->setFont(QFont("Times New Roman", 18, QFont::Bold, true ));
		blizzStr->setStyleSheet("color:white;" "background-color: steelblue;"); 
		//start GIF code
		QMovie *blizzardmovie=new QMovie("blizzard.gif");
		box-> setMovie(blizzardmovie);
		blizzardmovie-> start();
		//ok->setFixedSize(70,30);
		
	}
	else if(num == 9)  //Yeti
	{
		setWindowTitle(QString("Attack by Yeti!"));
		resize(350,350);
		box->setFixedSize(350,350);
		QLabel *yetiStr = new QLabel(qstr);
		yetiStr->setFixedSize(320,35);
		
		yetiStr->setFont(QFont("Times New Roman", 18, QFont::Bold, true));
		yetiStr->setStyleSheet("color: mediumblue;" "background-color: skyblue;");
		
		layout->addWidget(yetiStr,5,0);
		layout->addWidget(space, 1,0);
		layout->addWidget(space, 2,0);
		layout->addWidget(space, 3,0);
		layout->addWidget(space, 4,0);
		layout->addWidget(ok,6,0);
		
		//start GIF code
		QMovie *yetimovie=new QMovie("YETI.gif");
		box-> setMovie(yetimovie);
		yetimovie-> start();
		//ok->setFixedSize(70,30);
		
	}
	else if(num == 10) //Medicine error
	{
		setWindowTitle(QString("Error!"));
		resize(100,100);
		QLabel *medStr = new QLabel(QString("Error. No medicine to use."));
		layout->addWidget(medStr,0,0);
		layout->addWidget(ok,4,0);
		medStr->setFont(QFont("Times New Roman", 16, QFont::Bold, true));
		medStr->setStyleSheet("color:red;");
		
	}

	setLayout(layout);

	//Connects buttons to slots
	connect(ok, SIGNAL(clicked()), this, SLOT(closeThis()));
	connect(exit, SIGNAL(clicked()), this, SLOT(close()));
}

//Closes the pop up window
void GenericWindow:: close()
{
	exit(0);
}
void GenericWindow:: closeThis()
{
	clock->start(3000);
	this->hide();
}
//Returns how many days was specified
int GenericWindow:: getRestDays()
{
	if(rest->text().toInt() > 8)
		return 8;
	else
		return rest->text().toInt();
}
